const express = require("express");
const db = require("../db/index");
const router = express.Router();

router.get("/list", (req, res) => {
  const sql = "SELECT * FROM category";
  db.query(sql, (err, result) => {
    if (err) {
      res.cc(err);
    }
    res.send({
      status: 0,
      message: "获取分类列表成功",
      data: result,
    });
  });
});

// 获取分类标签名称接口
router.get("/:id", (req, res) => {
  const sql = "SELECT * FROM category WHERE id = ?";
  db.query(sql, [req.params.id], (err, result) => {
    if (err) {
      res.cc(err);
    }
    if (result.length === 0) {
      return res.cc("分类标签不存在");
    }
    res.send({
      status: 0,
      message: "获取分类标签名称成功",
      data: result[0],
    });
  });
});

module.exports = router;
